<?php
/**
 * Created by PhpStorm.
 * Script Name: Common.php
 * Create: 12/26/22 7:26 PM
 * Description:
 * Author: fudaoji<fdj@kuryun.cn>
 */

namespace plugin\wechat\app\service;

use EasyOpen\Tencent\Client as TencentCli;

class Common
{
    /**
     * 系统保留redis database
     * @return array|mixed|null
     * Author: fudaoji<fdj@kuryun.cn>
     */
    static function deserveRedis(){
        $config = config('redis.default');
        $options = [
            'prefix' => $config['prefix'],
            'parameters' => [
                'database' => $config['database'],
            ],
        ];
        return new \Predis\Client('tcp://'.$config['host'].':' . $config['port'], $options);
    }

    /**
     * 账号接入状态
     * @param null $id
     * @return array|mixed
     * Author: fudaoji<fdj@kuryun.cn>
     */
    static function platformStatus($id = null){
        $list = [
            0 => '未接入',
            1 => '接入'
        ];
        return isset($list[$id]) ? $list[$id] : $list;
    }

    /**
     * 微信开放平台请求端
     * @return TencentCli
     * Author: fudaoji<fdj@kuryun.cn>
     */
    static function tencentOpenCli(){
        return new TencentCli();
    }

    /**
     * 账号状态
     * @param null $id
     * @return array|mixed
     * Author: fudaoji<fdj@kuryun.cn>
     */
    public static function accountStatus($id = null){
        $list = [
            1 => '正常',
            14 => '已注销',
            16 => '已封禁',
            18 => '已告警',
            19 => '已冻结'
        ];
        return isset($list[$id]) ? $list[$id] : $list;
    }
}